package com.buymobile.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.buymobile.domain.Company;
import com.buymobile.domain.Property;
import com.buymobile.domain.Type;
import com.buymobile.domain.Value;
import com.buymobile.service.CompanyService;

@Controller
@RequestMapping("/company")
public class CompanyController {
	
	private CompanyService companyService;
	
	@Autowired
	public void setCompanyService(CompanyService companyService) {
		this.companyService = companyService;
	}
	
	@RequestMapping(value="findList")
	public String findList(Model model){
		
		Map map = new HashMap();
		int count = companyService.findCount(map);
		List list = companyService.findList(map);
		model.addAttribute("list", list);
		return "manager/company/list";
	}
	
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String setAddTypeForm(){
		return "manager/company/add";
	}
	
	@RequestMapping(value="/save",method=RequestMethod.POST)
	public String save(@ModelAttribute Company company){
		companyService.save(company);
		return "redirect:/company/findList";
	}
	
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	public String edit(@PathVariable("id") Integer id,Model model){
		
		Company company = companyService.get(id);
		model.addAttribute("obj", company);
		return "manager/company/edit";
	}
	
	@RequestMapping(value="/update",method=RequestMethod.POST)
	public String update(@ModelAttribute Company company){
		companyService.update(company);
		return "redirect:/company/findList";
	}
}
